import api from '@/common/api/api.js';
import env from '@/common/api/env.js';

// npm install amap-wx
// 需要先安装依赖才能import，不然会报错
import amap from 'amap-wx';

const defaultWaterMark = 'wm-datetime';
const keyWeather = 'min_pro_wm_weather';
const keyLocation = 'min_pro_location_data';
const keyConfigure = 'min_pro_configure';
const appName = 'Ai'

export default {
	pickerTempShowDashTime: 11, // 选中模板后显示虚线框的次数
	pickerTempShowDashTimeRate: 5, // 选中模板后显示虚线框的频率（4，则每隔4次刷新显示一次）
	width: 235,
	height: 113,
	autoRunDelay: 1000,
	tipMarginTop: 6,
	isFromApp: false,
	appName: appName,
	tag: appName + '水印相机已验证时间地点真实性',
	appTag: appName + '水印',
	appTag2: '- 相 机 -',
	shareTitle: '我正在使用' + appName + '水印相机',
	baseOpacity: 0.90,

	isClickedTempMark: false,

	// 查询水印模版的初始配置
	getInitConfigure(type) {
		console.log("type：", type)
		let options = [];
		// disable 0不可用 1|可用
		// checked - 0|未选择 1|已选中 
		// isMore - 0|没有右箭头  1|有右箭头
		// undraw 不绘制到画布中
		let data = {};

		if (type === 'wm-datetime') {
			let time = { name: '时间', type: 'time', value: '', checked: 1, isMore: 0, disable: 0 };
			let place = { name: '地点', type: 'place', value: '', checked: 1, isMore: 1, disable: 1 };
			let remark = { name: '备注', type: 'remark', value: '', checked: 0, isMore: 1, disable: 1 };
			let point = { name: '经纬度', type: 'point', value: '', checked: 0, isMore: 0, disable: 1 };
			options = [time, place, remark, point];
			data.opacity = 70;
		} else if (type && type.search('wm-project-record') !== -1) {
			let time = { name: '时      间', type: 'time', value: '', checked: 1, isMore: 0, disable: 0 };
			let place = { name: '地      点', type: 'place', value: '', checked: 0, isMore: 1, disable: 1 };
			let title = { name: '标      题', type: 'title', value: '', checked: 1, isMore: 1, disable: 0 };
			let point = { name: '经  纬 度', type: 'point', value: '', checked: 0, isMore: 0, disable: 1 };
			let weather = { name: '天      气', type: 'weather', value: '', checked: 0, isMore: 0, disable: 1 };
			let remark = { name: '备      注', type: 'remark', value: '', checked: 0, isMore: 1, disable: 1 };

			// 工程记录
			if (type === 'wm-project-record') {
				let sg_1 = { name: '施工内容', type: 'shigongneirong', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_2 = { name: '施工单位', type: 'shigongdanwei', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_3 = { name: '施工区域', type: 'shigongquyu', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_4 = { name: '监理单位', type: 'jianlidanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_5 = { name: '设计单位', type: 'shejidanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				options = [time, place, title, point, weather, remark, sg_1, sg_2, sg_3, sg_4, sg_5];
			}
			// 工程验收
			else if (type === 'wm-project-record-yanshou') {
				let sg_1 = { name: '验收区域', type: 'yanshouquyu', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_2 = { name: '验收内容', type: 'yanshouneirong', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_3 = { name: '是否合格', type: 'shifouhege', value: '', checked: 1, isMore: 1, disable: 1 };
				options = [time, place, title, sg_1, sg_2, sg_3];
			}
			// 施工前 中 后
			else if (type === 'wm-project-record-qian' || type === 'wm-project-record-zhong' || type === 'wm-project-record-hou') {
				let sg_1 = { name: '施工区域', type: 'shigongquyu', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_2 = { name: '施工内容', type: 'shigongneirong', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_3 = { name: '施工负责人', type: 'shigongfuzeren', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_4 = { name: '监理负责人', type: 'jianlifuzeren', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_5 = { name: '施工单位', type: 'shigongdanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_6 = { name: '监理单位', type: 'jianlidanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				options = [time, place, title, point, weather, sg_1, sg_2, sg_3, sg_4, remark, sg_5, sg_6];
			}
			// 项目巡检
			else if (type === 'wm-project-record-xunjian') {
				// let place = {name:'地      点',type:'place', value:'', checked: 0, isMore:1, disable:1};
				let sg_1 = { name: '巡检类型', type: 'xunjianleixing', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_2 = { name: '巡检内容', type: 'xunjianneirong', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_3 = { name: '巡检人员', type: 'xunjianrenyuan', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_4 = { name: '施工单位', type: 'shigongdanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_5 = { name: '监理单位', type: 'jianlidanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				options = [time, place, title, sg_1, sg_2, sg_3, weather, point, remark, sg_4, sg_5];
			}
			// 记工水印
			else if (type === 'wm-project-record-jigong') {
				let time = { name: '时间', type: 'time', value: '', checked: 1, isMore: 0, disable: 0 };
				let place = { name: '地点', type: 'place', value: '', checked: 1, isMore: 1, disable: 1 };
				let title = { name: '标题', type: 'title', value: '', checked: 1, isMore: 1, disable: 0 };
				let weather = { name: '天气', type: 'weather', value: '', checked: 0, isMore: 0, disable: 1 };
				let remark = { name: '备注', type: 'remark', value: '', checked: 0, isMore: 1, disable: 1 };
				let jigong = { name: '记工', type: 'jigong', value: '', checked: 1, isMore: 1, disable: 0, noModTitle: 1, tip: '请输入工时，例：1个工' };
				options = [title, time, place, weather, jigong, remark];
			}
			// 会议记录
			else if (type === 'wm-project-record-huiyi') {
				place.checked = 1;
				let sg_1 = { name: '会议名称', type: 'huiyimingcheng', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_2 = { name: '会议内容', type: 'huiyineirong', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_3 = { name: '参会人员', type: 'canhuirenyuan', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_4 = { name: '施工单位', type: 'shigongdanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_5 = { name: '监理单位', type: 'jianlidanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				options = [time, place, title, sg_1, sg_2, sg_3, weather, point, remark, sg_4, sg_5];
			}
			// 装修施工记录
			else if (type === 'wm-project-record-zxsgjl') {
				let sg_1 = { name: '施工区域', type: 'shigongquyu', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_2 = { name: '施工内容', type: 'shigongneirong', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_3 = { name: '施工负责人', type: 'shigongfuzeren', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_4 = { name: '建设单位', type: 'jianshedanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_5 = { name: '施工单位', type: 'shigongdanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_6 = { name: '监理单位', type: 'jianlidanwei', value: '', checked: 0, isMore: 1, disable: 1 };

				point.checked = 1;
				weather.checked = 1;
				place.checked = 1;

				options = [time, place, title, point, weather, sg_1, sg_2, sg_3, sg_4, sg_5, remark];
			}
			// 水电开槽
			else if (type === 'wm-project-record-sdkc') {
				place.checked = 1;

				let sg_1 = { name: '施工区域', type: 'shigongquyu', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_2 = { name: '施工内容', type: 'shigongneirong', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_3 = { name: '施工负责人', type: 'shigongfuzeren', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_4 = { name: '监理负责人', type: 'jianlifuzeren', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_5 = { name: '建设单位', type: 'jianshedanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_6 = { name: '施工单位', type: 'shigongdanwei', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_7 = { name: '监理单位', type: 'jianlidanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_8 = { name: '设计单位', type: 'shejidanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				options = [time, place, title, point, weather, sg_1, sg_2, sg_3, sg_4, remark, sg_5, sg_6, sg_7, sg_8];
			}
			// 水电预埋 || 防水堵漏
			else if (type === 'wm-project-record-sdym' || type === 'wm-project-record-fsdl' || type === 'wm-project-record-dmzp' || type === 'wm-project-record-sndd') {
				place.checked = 1;
				let sg_1 = { name: '施工区域', type: 'shigongquyu', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_2 = { name: '施工内容', type: 'shigongneirong', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_3 = { name: '施工负责人', type: 'shigongfuzeren', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_4 = { name: '监理负责人', type: 'jianlifuzeren', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_5 = { name: '建设单位', type: 'jianshedanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_6 = { name: '监理单位', type: 'jianlidanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				let sg_7 = { name: '施工单位', type: 'shigongdanwei', value: '', checked: 1, isMore: 1, disable: 1 };
				let sg_8 = { name: '设计单位', type: 'shejidanwei', value: '', checked: 0, isMore: 1, disable: 1 };
				place.checked = 1;
				if (type === 'wm-project-record-sndd') {
					sg_3.checked = 1;
				}

				options = [time, place, title, point, weather, sg_1, sg_2, sg_3, sg_4, remark, sg_5, sg_6, sg_7, sg_8];
			}

			data.opacity = 30;
		} else if (type === 'wm-scene') {
			let title = { name: '标题', type: 'title', value: '现场拍照', checked: 1, isMore: 0, disable: 0 };
			let time = { name: '时间', type: 'time', value: '', checked: 1, isMore: 0, disable: 0 };
			let place = { name: '地点', type: 'place', value: '', checked: 1, isMore: 1, disable: 1 };
			let point = { name: '经纬度', type: 'point', value: '', checked: 0, isMore: 0, disable: 1 };
			let weather = { name: '天气', type: 'weather', value: '', checked: 0, isMore: 0, disable: 1 };
			let remark = { name: '备注', type: 'remark', value: '', checked: 0, isMore: 1, disable: 1 };
			options = [time, title, place, point, weather, remark];
			data.opacity = 100;
		} else if (type === 'wm-clock') {
			let time = { name: '时间', type: 'time', value: '', checked: 1, isMore: 0, disable: 0 };
			let place = { name: '地点', type: 'place', value: '', checked: 1, isMore: 1, disable: 1 };
			let weather = { name: '天气', type: 'weather', value: '', checked: 0, isMore: 0, disable: 1 };
			let remark = { name: '备注', type: 'remark', value: '', checked: 0, isMore: 1, disable: 1 };
			options = [time, place, weather, remark];
			data.opacity = 30;
		}
		// 考勤打卡
		else if (type === 'wm-work' || type === 'wm-work-remark' || type === 'wm-work-start' || type === 'wm-work-end') {
			let time = { name: '时间', type: 'time', value: '', checked: 1, isMore: 0, disable: 0 };
			let place = { name: '地点', type: 'place', value: '', checked: 0, isMore: 1, disable: 1 };
			let title = { name: '标题', type: 'title', value: '', checked: 1, isMore: 1, disable: 0 };
			let point = { name: '经纬度', type: 'point', value: '', checked: 0, isMore: 0, disable: 1 };
			let weather = { name: '天气', type: 'weather', value: '', checked: 1, isMore: 0, disable: 1 };
			let remark = { name: '备注', type: 'remark', value: '', checked: 0, isMore: 1, disable: 1 };

			if (type === 'wm-work-remark') {
				options = [time, place, title, point, weather, remark];
			} else {
				options = [time, place, title, weather, remark];
			}
			data.opacity = 100;
		}
		// 物业管理
		else if (type && type.search('wm-property') !== -1) {
			let title = { name: '标      题', type: 'title', value: '', checked: 1, isMore: 0, disable: 0 };
			let time = { name: '时      间', type: 'time', value: '', checked: 1, isMore: 0, disable: 0 };
			let place = { name: '地      点', type: 'place', value: '', checked: 1, isMore: 1, disable: 1 };
			let remark = { name: '备      注', type: 'remark', value: '', checked: 0, isMore: 1, disable: 1 };
			let weather = { name: '天      气', type: 'weather', value: '', checked: 0, isMore: 0, disable: 1 };
			let area = { name: '工作区域', type: 'work_area', value: '', checked: 0, isMore: 1, disable: 1 };
			let building = { name: '楼栋单元', type: 'building_unit', value: '', checked: 0, isMore: 1, disable: 1 };
			let unit = { name: '物业单位', type: 'work_unit', value: '', checked: 0, isMore: 1, disable: 1 };
			let xunjianneirong = { name: '巡检内容', type: 'xunjianneirong', value: '', checked: 0, isMore: 1, disable: 1 };
			let xunluoren = { name: '巡  逻  人', type: 'xunluoren', value: '', checked: 0, isMore: 1, disable: 1 };
			let xunluoquyu = { name: '巡逻区域', type: 'xunluoquyu', value: '', checked: 0, isMore: 1, disable: 1 };
			let xunjianren = { name: '巡  检  人', type: 'xunjianren', value: '', checked: 0, isMore: 1, disable: 1 };
			let xunjianleixing = { name: '巡检类型', type: 'xunjianleixing', value: '', checked: 0, isMore: 1, disable: 1 };
			let xunjianjieguo = { name: '巡检结果', type: 'xunjianjieguo', value: '', checked: 0, isMore: 1, disable: 1 };
			let xunjianquyu = { name: '巡检区域', type: 'xunjianquyu', value: '', checked: 0, isMore: 1, disable: 1 };
			let xiaoqumingcheng = { name: '小区名称', type: 'xiaoqumingcheng', value: '', checked: 0, isMore: 1, disable: 1 };
			let weixiuren = { name: '维  修  人', type: 'weixiuren', value: '', checked: 0, isMore: 1, disable: 1 };
			let weixiuneirong = { name: '维修内容', type: 'weixiuneirong', value: '', checked: 0, isMore: 1, disable: 1 };
			let weixiuweizhi = { name: '维修位置', type: 'weixiuweizhi', value: '', checked: 0, isMore: 1, disable: 1 };

			// 物业管理
			if (type === 'wm-property') {
				area.checked = 1;
				options = [title, time, place, area, building, unit, remark];
			}
			// 物业巡检
			else if (type === 'wm-property-wyxj') {
				xunjianneirong.checked = 1;
				options = [title, time, place, weather, building, xunjianneirong, xunjianren, remark];
			}
			// 治安巡逻
			else if (type === 'wm-property-zaxl') {
				xunluoquyu.checked = 1;
				options = [title, time, place, building, xunluoren, xunluoquyu, unit, remark];
			}
			// 值班巡检
			else if (type === 'wm-property-zbxl') {
				xunjianleixing.checked = 1;
				xunjianneirong.checked = 1;
				unit.checked = 1;
				options = [title, time, place, weather, xunjianren, xunjianleixing, xunjianneirong, xunjianjieguo, xunjianquyu, xiaoqumingcheng, unit];
			}
			// 故障维修
			else if (type === 'wm-property-gzwx') {
				weixiuneirong.checked = 1;
				xiaoqumingcheng.checked = 1;
				unit.checked = 1;
				options = [title, time, place, weather, weixiuren, weixiuneirong, xiaoqumingcheng, weixiuweizhi, unit];
			}
			data.opacity = 30;
		}
		// 地点水印
		else if (type === 'wm-place') {
			let time = { name: '时间', type: 'time', value: '', checked: 1, isMore: 0, disable: 0 };
			let place = { name: '地点', type: 'place', value: '', checked: 1, isMore: 1, disable: 0 };
			let point = { name: '经纬度', type: 'point', value: '', checked: 0, isMore: 0, disable: 1 };
			let weather = { name: '天气', type: 'weather', value: '', checked: 0, isMore: 0, disable: 1 };
			let remark = { name: '备注', type: 'remark', value: '', checked: 0, isMore: 1, disable: 1 };
			options = [time, place, point, weather, remark];
			data.opacity = 100;
		}
		// 天气水印
		else if (type === 'wm-weather') {
			let time = { name: '时间', type: 'time', value: '', checked: 1, isMore: 0, disable: 0 };
			let place = { name: '地点', type: 'place', value: '', checked: 0, isMore: 1, disable: 1 };
			let weather = { name: '天气', type: 'weather', value: '', checked: 1, isMore: 0, disable: 0 };
			let remark = { name: '备注', type: 'remark', value: '', checked: 0, isMore: 1, disable: 1 };
			options = [time, place, weather, remark];
			data.opacity = 100;
		}

		let verificationText = { name: '验证提示', type: 'verificationText', value: '', checked: 1, isMore: 0, disable: 1, undraw: 1 };

		options.push(verificationText);

		// 依靠version版本来控制是否获取初始配置
		data.opacity = 30;
		data.size = 50;
		data.zoom = 50;
		data.version = env.version;
		data.list = options;

		return data;
	},

	// 查询水印配置
	queryWaterMarkConfigure(waterMarkType, info) {
		let configure = uni.getStorageSync(keyConfigure + waterMarkType);

		if (!configure || !configure.version || configure.version < env.version) {
			configure = this.getInitConfigure(waterMarkType);
		}


		configure.width = configure.width ? configure.width : this.width;
		configure.height = configure.height ? configure.height : this.height;

		// 实时动态更新一些常变动的字段
		if (info) {
			let options = configure.list;
			options.forEach(item => {
				switch (item.type) {
					case 'time':
						let date = info.year + '-' + info.month + '-' + info.day + ' ' + info.hour + ':' + info.min + ' ' + info.weekDay;
						item.value = date;
						break;
					case 'place':
						if (!item.value) {
							item.value = info.location;
						}
						break;
					case 'point':
						item.value = {
							desc: 'N ' + (info.latitude || '0') + '°,' + 'E ' + (info.longitude || '0') + '°',
							latitude: info.latitude || 0,
							longitude: info.longitude || 0
						};
						// item.value = 'N '+info.latitude+'°，'+'E '+info.longitude+'°';
						break;
					case 'weather':
						item.value = info.weather + ' ' + info.tem + '℃';
						break;
				}
			});

			// console.error("初始化水印模板配置:",configure);

			this.updateWaterMarkConfigure(waterMarkType, configure);
		}

		// console.error("加载水印模版最新配置：",configure, ' info',info);
		return configure;
	},

	updateListDialogStatus(value) {
		uni.setStorageSync('listDialogStatus', value);
	},

	queryListDialogStatus() {
		return uni.getStorageSync('listDialogStatus');
	},

	// 更新水印配置
	updateWaterMarkConfigure(waterMarkType, configure) {
		// let allConfigure = uni.getStorageSync(keyConfigure) || {};
		// allConfigure[waterMarkType] = configure;
		// console.error("保存总配置：",allConfigure);
		// console.log("waterMarkType：",waterMarkType)
		// console.log("configure：",coonf)
		uni.setStorageSync(keyConfigure + waterMarkType, configure);
	},
	// 更新天气
	updateWeather(data) {
		if (data) {
			data.updateTime = new Date().getTime();
			uni.setStorageSync(keyWeather, data);
		}
	},

	// 查询当前使用的水印模版名字
	queryWaterMarkName() {
		let name = uni.getStorageSync('current_water_mark_name') || defaultWaterMark;
		// console.log("当前模版名字：",name)
		return name;
	},

	// 更新当前使用的水印模版名字
	updateWaterMarkName(value) {
		return uni.setStorageSync('current_water_mark_name', value);
	},

	// 查询当前使用的水印模版菜单id
	queryWaterMarkMenuId() {
		return uni.getStorageSync('current_water_mark_menuid') || 1;
	},

	// 更新当前使用的水印模版菜单
	updateWaterMarkMenuId(value) {
		return uni.setStorageSync('current_water_mark_menuid', value);
	},

	// 查询天气
	queryWeather() {
		return new Promise((resolve, rejected) => {
			resolve("asd");
			return;
			// let weather = uni.getStorageSync(keyWeather);
			// let nowTime = new Date().getTime();

			// // 如果还没有过期（5小时以内）就用缓存数据
			// if((weather.version && weather.version >= env.version) && (weather && weather.updateTime > (nowTime - 18000000))){
			// 	// console.error("返回天气缓存数据，剩余过期时间",(weather.updateTime - (nowTime - 18000000)))
			// 	resolve(weather);
			// 	return;
			// }

			// let amapPlugin = new amap.AMapWX({key: env.gaodeAppCode });

			// let that = this;
			// //执行实时天气信息查询
			// amapPlugin.getWeather({
			// 	success: function(data) {
			// 		console.log(data) //天气数据
			// 		console.error("天气查询成功：",data);

			// 		let liveData = data.liveData;

			// 		let wea = liveData.weather;
			// 		let tem = liveData.temperature;
			// 		let win = liveData.winddirection+'风';

			// 		let weatherData = { weather: wea, tem: tem, win: win, version: env.version };
			// 		that.updateWeather(weatherData);
			// 		resolve(weatherData);
			// 	},
			// 	fail: function(info) {
			// 		console.error("天气查询失败：",info);
			// 		rejected(info);
			// 	}
			// })
		});
	},
	// 获取透明指数
	getItemOpacity(waterMarkType, data) {
		if (!data) {
			data = this.queryWaterMarkConfigure(waterMarkType);
		}

		let op = data.opacity || 0;
		op = 100 - op;
		let value = (op / 100.0);
		return value;
	},
	// 获取缩放指数
	getItemZoom(waterMarkType, data) {
		if (!data) {
			data = this.queryWaterMarkConfigure(waterMarkType);
		}

		if (data.zoom && data.zoom != 50) {
			if (data.zoom > 50) {
				return 1 + (data.zoom - 50) * 0.01;
			} else {
				return 1 - (50 - data.zoom) * 0.01;
			}
		} else {
			return 1;
		}
	},
	getItem(waterMarkType, flagKeyName, data) {
		if (!data) {
			data = this.queryWaterMarkConfigure(waterMarkType);
		}

		if (flagKeyName === 'widthAndHeight') {
			return { width: data.width, height: data.height, boxHeight: data.boxHeight };
		}

		let list = data.list;

		if (list && list.length > 0) {
			let findItem = list.find(item => {
				if (item.type === flagKeyName) {
					return true;
				}
			});

			return findItem || {};
		}

		return {};
	},
	// 更新位置信息
	updateLocation(data) {
		if (data) {
			data.updateTime = new Date().getTime();
			uni.setStorageSync(keyLocation, data);
		}
	},
	// 查询位置信息
	queryLocation() {
		return new Promise((resolve, rejected) => {
			// resolve("测试");
			// return

			let location = uni.getStorageSync(keyLocation);
			let nowTime = new Date().getTime();

			// 如果还没有过期（5小时以内）就用缓存数据
			if ((location.version || location.version >= env.version) && (location && location.updateTime > (nowTime - 18000000))) {
				// console.error("返回定位缓存数据，剩余过期时间",(location.updateTime - (nowTime - 18000000), '数据：',JSON.stringify(location)));
				//resolve(location);
				//return;
			}

			let amapPlugin = new amap.AMapWX({ key: env.gaodeAppCode });
			let that = this;

			// 成功获取位置
			amapPlugin.getRegeo({
				success: (data) => {
					if (data && data.length > 0) {
						let location = {
							longitude: data[0].longitude,
							latitude: data[0].latitude,
							poiName: data[0].name,
							city: data[0].regeocodeData.addressComponent.city,
							province: data[0].regeocodeData.addressComponent.province,
							pois: data[0].regeocodeData.pois,
							version: env.version,
						}

						console.error("定位数据：", data);

						if (location.province === '北京市' || location.province === '上海市' || location.province === '天津市' || location.province === '重庆市') {
							location.city = data[0].regeocodeData.addressComponent.district;
						}

						let sub = location.poiName.substring(0, location.city.length);
						let issame = sub === location.city;
						location.address = location.province + (issame ? '' : location.city) + location.poiName;

						that.updateLocation(location);
						resolve(location);
					} else {
						rejected({ message: '定位失败，未知错误:' + JSON.stringify(data || "{}") });
					}
				},
				// 获取位置失败
				fail: (err) => {
					console.error('返回错误', JSON.stringify(err));
					rejected(err);
				}
			});
		})
	},

	// 添加照片到本地相册
	addPhoto2LocalAlbum(path, isFromApp) {
		if (!path) return;

		let list = this.queryPhotoFromLocalAlbum();

		let time = new Date();
		let m = time.getMonth() + 1;
		m = m < 10 ? '0' + m : m;

		let d = time.getDate();
		d = d < 10 ? '0' + d : d;

		let timeInfo = time.getFullYear() + '-' + m + '-' + d;
		if (list) {
			let findItem = list.find(item => {
				return item.date === timeInfo;
			});

			// 如果不存在就创建
			if (!findItem) {
				list.unshift({ date: timeInfo, list: [path] });
			} else {
				if (!findItem.list) {
					findItem.list = [];
				}

				findItem.list.unshift(path);
			}
		} else {
			list = [];
			list.unshift({ date: timeInfo, list: [path] });
		}

		uni.setStorageSync('appLocalAlbum', list);
	},

	updatePhotoFromLocalAlbum(data) {
		uni.setStorageSync('appLocalAlbum', data);
	},

	// 查询本地相册
	queryPhotoFromLocalAlbum() {
		let list = uni.getStorageSync('appLocalAlbum');
		return list;
	},

	// updateIsFromApp(data){
	// 	uni.setStorageSync('isFromApp',data);
	// },

	// // 查询是否来自app
	// queryIsFromApp(){
	// 	return uni.getStorageSync('isFromApp');
	// },

	// 查询第一张本地相册照片
	queryPreviewImage() {
		let list = this.queryPhotoFromLocalAlbum();
		if (list && list.length > 0) {
			let photos = list[0].list;
			if (photos && photos.length > 0) {
				return { img: photos[0], date: list[0].date };
			} else {
				return undefined;
			}
		} else {
			return undefined;
		}
	},

	deletePhotoFromLocalAlbum(obj) {
		if (!obj) return;

		let list = this.queryPhotoFromLocalAlbum();

		let findItemId = list.findIndex(item => {
			return item.date === obj.date;
		});

		let findItem = list[findItemId];

		if (findItem) {
			let photos = findItem.list;
			let findPhotoId = photos.findIndex(p => {
				return p === obj.img;
			});

			if (findPhotoId != -1) {
				photos.splice(findPhotoId, 1);
			}

			findItem.list = photos;

			// 当前日期已经没有照片了，就把日期也删除
			if (!photos || photos.length === 0) {
				list.splice(findItemId, 1);
			}

			this.updatePhotoFromLocalAlbum(list);
			return findPhotoId !== -1 ? 1 : 0;
		}

		return 0;
	}
}